package com.ruoyi.tzzl.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.tzzl.domain.WzComment;
import com.ruoyi.tzzl.domain.WzDynamic;
import com.ruoyi.tzzl.mapper.WzDynamicMapper;
import com.ruoyi.tzzl.mapper.WzProgramUserMapper;
import com.ruoyi.tzzl.service.*;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户动态Service业务层处理
 * @author by caoyong
 * @date 2022/11/18
 **/
@Service
public class WzDynamicServiceImpl extends ServiceImpl<WzDynamicMapper, WzDynamic> implements IWzDynamicService {

    @Autowired
    private WzDynamicMapper wzDynamicMapper;
    @Autowired
    private IWzCommentsService wzCommentsService;
    @Autowired
    private IWzProgramUserService userService;
    @Autowired
    private WzProgramUserMapper wzProgramUserMapper;
    @Autowired
    private IWzFocusonService wzFocusonService;
    @Autowired
    private IWzCertificationService wzCertificationService;
    @Autowired
    private IWzGiveLikeService wzGiveLikeService;


    /**查询用户动态信息
     * id 动态表id wid访问用户id  uid动态用户id  type: 0-女  1-男 2-附近的人 3-热门
     * */
    @Override
    public List<WzDynamic> getByWid(Long id,Long wid,Long uid,String type) {
        LambdaQueryWrapper<WzDynamic> lqw =new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(id)){
            lqw.eq(WzDynamic::getId,id);
        }
        if (ObjectUtils.isNotEmpty(uid)){
            lqw.eq(WzDynamic::getWid,uid);
        }
        if (ObjectUtils.isNotEmpty(type)){
            lqw.in(WzDynamic::getWid,userService.getByType(type));
        }
        if (ObjectUtils.isNotEmpty(type)){
            if (type.equals("3")){
                lqw.orderByDesc(WzDynamic::getLikenums);
            }else{
                lqw.orderByDesc(WzDynamic::getCreateTime);
            }
        }
       List<WzDynamic> list = this.list(lqw);
       if (ObjectUtils.isNotEmpty(list)){
           for (int i = 0; i < list.size(); i++) {
              List<WzComment>  list1 = wzCommentsService.getByDid(list.get(i).getId());
              list.get(i).setWzCommentList(list1);
              list.get(i).setCommentAmount(list1.size());
              list.get(i).setUser(wzProgramUserMapper.detailedProgramUser(list.get(i).getWid()));
              list.get(i).setAttention(wzFocusonService.judgeAttention(wid,list.get(i).getWid()));
              list.get(i).setAuthentication(wzCertificationService.getIfAuthentication(list.get(i).getWid()));
              list.get(i).setGiveAlike(wzGiveLikeService.judge(list.get(i).getId(),wid));
           }
       }
        return list;
    }

}
